package com.konne.nightmare.FastPublicOpinion.mvp.presenter;


import com.konne.nightmare.FastPublicOpinion.base.BaseMvpPresenter;
import com.konne.nightmare.FastPublicOpinion.base.OnLoadDataListener;
import com.konne.nightmare.FastPublicOpinion.bean.EventBean;
import com.konne.nightmare.FastPublicOpinion.bean.LoginBean;
import com.konne.nightmare.FastPublicOpinion.http.BaseResponse;
import com.konne.nightmare.FastPublicOpinion.http.RetrofitFactory;
import com.konne.nightmare.FastPublicOpinion.mvp.model.IEventFragmentModel;
import com.konne.nightmare.FastPublicOpinion.mvp.model.IHomeFragmentModel;
import com.konne.nightmare.FastPublicOpinion.mvp.model.impl.EventFragmentModelImpl;
import com.konne.nightmare.FastPublicOpinion.mvp.model.impl.HomeFragmentModelImpl;
import com.konne.nightmare.FastPublicOpinion.mvp.view.IEventFragmentView;
import com.konne.nightmare.FastPublicOpinion.mvp.view.IHomeFragmentView;
import com.konne.nightmare.FastPublicOpinion.utils.MMKVUtils;
import com.konne.nightmare.FastPublicOpinion.utils.Utils;

import org.json.JSONObject;

import java.util.List;


public class EventPresenter extends BaseMvpPresenter<IEventFragmentView> {
    private IEventFragmentModel iEventFragmentModel;

    public EventPresenter() {
        iEventFragmentModel = new EventFragmentModelImpl();
    }

    public void selectEventPlanList() {
        if (mView == null) return;
        JSONObject params = RetrofitFactory.getJsonParams();
        try {
            params.put("agencyId", mView.agencyId());
        } catch (Exception e) {

        }
        iEventFragmentModel.selectEventPlanList(params, new OnLoadDataListener<List<EventBean.RowsBean>>() {
            @Override
            public void onSuccess(BaseResponse<List<EventBean.RowsBean>> t) {
                getView().selectEventPlanList(t);
                getView().cancelLoadDialog();
            }

            @Override
            public void onFailure(String error) {
                getView().cancelLoadDialog();
            }
        });
    }

    public void updateEventPlan() {
        if (mView == null) return;
        JSONObject params = RetrofitFactory.getJsonParams();
        try {
            params.put("agencyId", mView.agencyId());
            params.put("eventId", mView.eventId());
        } catch (Exception e) {

        }
        iEventFragmentModel.updateEventPlan(params, new OnLoadDataListener<String>() {
            @Override
            public void onSuccess(BaseResponse<String> t) {
                getView().updateEventPlan(t);
                getView().cancelLoadDialog();
            }

            @Override
            public void onFailure(String error) {
                getView().cancelLoadDialog();
            }
        });
    }

    public void delete() {
        if (mView == null) return;
        JSONObject params = RetrofitFactory.getJsonParams();
        try {
            params.put("eventId", mView.eventId());
        } catch (Exception e) {

        }
        iEventFragmentModel.delete(params, new OnLoadDataListener<String>() {
            @Override
            public void onSuccess(BaseResponse<String> t) {
                getView().delete(t);
                getView().cancelLoadDialog();
            }

            @Override
            public void onFailure(String error) {
                getView().cancelLoadDialog();
            }
        });
    }

}
